﻿using AuthCenter.API.Application.Command.AccountRole;
using AuthCenter.API.DTOs;
using AuthCenter.Domain.Account;
using AuthCenter.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace AuthCenter.API.Controllers
{
    /// <summary>
    /// 用户角色控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class AccountRoleController : ControllerBase
    {
        private readonly IMediator mediator;

        public AccountRoleController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 用户分配角色接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<APIResult<int>> CreateAccountRole(CreateAccountRoleCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 通过部门查找用户接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<Tree>>> GetRoleUser([FromQuery]GetRoleUserCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 通过角色查找用户接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<AccountRoleDTO>>> RoleUser([FromQuery]FindRoleUserCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 删除员工接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<int>> DelRoleUser([FromQuery]DelRoleUserCommand request)
        {
            return mediator.Send(request);
        }
    }
}
